package is.olsenolsen;

import is.Exceptions.EmptyDeckException;
import java.util.ArrayList;


public class Player {
	int cards_in_hand;
	int score;
	Deck hand = new Deck(0);
	
	//Smidur f. Player
	Player(Deck deck, int nrCards, int score){
		this.score = score;
		//Starting hand
		try{
			this.hand.cards.addAll(deck.draw(nrCards));
			this.cards_in_hand = hand.cards.size();
		}
		catch(EmptyDeckException e){
		}
	}
	
	//Notkun: addScore(n)
	//Fyrir:  n er heiltala
	//Eftir:  score = score + n
	public void updateScore(int points){
		this.score += points;
	}
	
	//Notkun: b = drawFromHand(n)
	//Fyrir:  n er heiltala
	//Eftir:  b er ArrayList<Card> med n-stok
	public ArrayList<Card> drawFromHand(int nrCards) throws EmptyDeckException{
		try{
			ArrayList<Card> cards = hand.draw(nrCards);
			this.cards_in_hand -= nrCards;				
			return cards;
		}
		catch(EmptyDeckException e){
			throw new EmptyDeckException();
		}
		
	}
	
	//Notkun: addToHand(ArrayList<Card> cards)
	//Fyrir:  hand er ArrayList<Card>
	//Eftir:  Buid er ad baeta cards vid hand
	public void addToHand(ArrayList<Card> cards){
		this.hand.cards.addAll(cards);
		this.cards_in_hand += 1;
	}
	
}